<template>
  <div>
    <header-bar></header-bar>
    <loading v-if="isLoading"></loading>
    <div class="movie-content">
      <h1>影院热映</h1>
      <router-link class="img-list" :to="{name:'MovieView',params:{id:sub.id}}" v-for="(sub,index) in subjects"
                   :key="index">
        <div class="img">
          <img :src="sub.images.small" alt="">
          <div class="star">
            <p>{{sub.title}}</p>
            <rating v-if="sub.rating" :rating="sub.rating"></rating>
          </div>
        </div>
      </router-link>
    </div>
  </div>
</template>

<script>
  import HeaderBar from './HeaderBar'
  import Rating from '../public/Rating'
  import Loading from '../public/Loading'

  export default {
    name: 'HotMovie',
    components: {
      HeaderBar,
      Rating,
      Loading
    },
    data() {
      return {
        subjects: [],
        isLoading:true
      }
    },
    created() {
      this.axios.get('/api/movie/in_theaters?count=25')
        .then((res) => {
          this.isLoading = false
          let subjects = res.data.subjects
          this.subjects = subjects
        })
        .catch((err) => console.log(err))
    }
  }
</script>

<style lang="scss">
  .movie-content {
    margin-top: 47px;
    padding: 20px 0;
    h1 {
      font-size: 24px;
      margin-bottom: 6px;
      padding: 15px 5px;
      color: #494949;
    }
  }

  .img-list {
    width: 33%;
    margin-bottom: 20px;
    display: inline-block;
    text-align: center;
    padding-left: 8px;
    box-sizing: border-box;
  }

  .star {
    position: absolute;
    bottom: -40px;
    width: 98px;
    height: 40px;
    p {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      width: 98px;
      color: #494949;
      font-size: 13px;
    }
    .star-full {
      display: inline-block;
      width: 10px;
      height: 10px;
      background-image: url();
      background-size: cover;
    }

    .star-gray {
      display: inline-block;
      width: 10px;
      height: 10px;
      background-image: url();
      background-size: cover;
    }

    .star-half {
      display: inline-block;
      width: 10px;
      height: 10px;
      background-image: url();
      background-size: cover;
    }
    .average {
      font-size: 12px;
    }
  }

  .img {
    position: relative;
    display: inline-block;
    width: 98px;
    height: 140px;
    margin-bottom: 30px;
    img {
      width: 100%;
      height: 100%;
    }
  }
</style>
